import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

class HttpPayslipsService {
  static Future<Response> dashboardPayslips() {
    return BaseConfig.httpBase.get('/api/dashboard/payslips', {});
  }

  static Future<Response> payslipsList([String type]) {
    return BaseConfig.httpBase.get('/api/payslips', {
      'type': type,
    });
  }

  static Future<Response> payslipsDetails(int id) {
    return BaseConfig.httpBase.get('/api/payslips/$id', {});
  }

  static Future<Response> payslipsBatchDelete(List<int> ids) {
    return BaseConfig.httpBase.postJson('/api/payslips/batch_delete', {
      'ids': ids,
    });
  }

  static Future<Response> payslipsDelete(int id) {
    return BaseConfig.httpBase.deleteJson('/api/payslips/$id', {});
  }

  static Future<Response> calculateWorkingDays(
    List<int> employeeIds,
    String startDate,
    String endDate,
  ) {
    return BaseConfig.httpBase
        .postJson('/api/payslips/calculate_working_days', {
      'employee_ids': employeeIds,
      'start_date': startDate,
      'end_date': endDate,
    });
  }

  static Future<Response> payslipsGenerate(
    List employeeWorkDays,
    String startDate,
    String endDate,
  ) {
    return BaseConfig.httpBase.postJson('/api/payslips/generate', {
      'employee_ids': employeeWorkDays,
      'start_date': startDate,
      'end_date': endDate,
    });
  }

  static Future<Response> payslipsPay(
    List<int> payslipIds, {
    int paymentTypeId,
    int accountId,
    String number,
    String issuedAt,
    String chequeNumber,
    String note,
    List attachment_ids,
  }) {
    return BaseConfig.httpBase.postJson('/api/payslips/pay', {
      'payslip_ids': payslipIds,
      'payment_type_id': paymentTypeId,
      'account_id': accountId,
      // 'number': number,
      'issued_at': issuedAt,
      'cheque_number': chequeNumber,
      'notes': note,
      'attachment_ids': attachment_ids ?? [],
    });
  }

  static Future<Response> updatePayslip(
    int id, {
    String contribution,
    double contribution_amount,
    List income_data,
    List deduction_data,
  }) {
    return BaseConfig.httpBase.putJson('/api/payslips/$id', {
      "contribution": contribution,
      "contribution_amount": contribution_amount,
      "income_data": income_data,
      "deduction_data": deduction_data
    });
  }
}
